package com.stadium.service.impl;

import com.stadium.common.utils.SqlMapper;
import com.stadium.common.utils.UserUtils;
import com.stadium.dto.SysTokenDto;
import com.stadium.entity.SysToken;
import com.stadium.mapper.SysTokenMP;
import com.stadium.service.SysTokenSV;
import com.stadium.vo.SysTokenVo;
import com.stadium.vo.searchVo.SysTokenSearchVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class SysTokenSVI implements SysTokenSV {
	@Autowired
	private SysTokenMP mapper;
	@Autowired
	private SqlMapper sqlMapper;

	@Override
	public List<SysToken> queryBySQL(String sql,Map<String, Object> map) {
		return sqlMapper.selectList(sql, map, SysToken.class);
	}

    @Override
    public void save(SysTokenVo sysTokenVo) {
        SysToken sysToken = new  SysToken();
        BeanUtils.copyProperties(sysTokenVo,sysToken);
        sysToken.setUpdateUser(UserUtils.getUserId());
        sysToken.setCreateUser(UserUtils.getUserId());
        mapper.save(sysToken);
    }

    @Override
    public void update(SysTokenVo sysTokenVo) {
        SysToken sysToken = new  SysToken();
        BeanUtils.copyProperties(sysTokenVo,sysToken);
        sysToken.setUpdateUser(UserUtils.getUserId());
        mapper.update(sysToken);
    }

    @Override
    public void saveBatch(List<SysToken> list) {
        mapper.saveBatch(list);
    }

    @Override
    public void delete(String id) {
        mapper.delete(id);
    }

    @Override
    public void deleteBatch(String[] ids) {
        mapper.deleteBatch(ids);
    }


    @Override
    public List<SysTokenDto> query(SysTokenSearchVo searchVo) {
        return mapper.query(searchVo);
    }

    @Override
    public SysTokenDto get(String id) {
        return mapper.get(id);
    }

    @Override
    public int getCount(SysTokenSearchVo searchVo) {
        return mapper.getCount(searchVo);
    }

    @Override
    public SysTokenDto getByUserId(String userId) {
        return mapper.getByUserId(userId);
    }

}
